# 异常捕获
try:
    print(num)
except NameError as E:
    print('异常信息', E)

try:
    open('b.txt', 'r')
except IOError as E:
    print('异常信息', E)
# 所有非退出异常的公共基类
try:
    open('c.txt', 'r')
except Exception as E:
    print('异常信息', E)

try:
    open('a.txt', 'r')
except Exception as E:
    print('异常信息', E)
else:
    print('无异常，nice')

try:
    open('b.txt', 'r')
except Exception as E:
    print('异常信息', E)
else:
    print('无异常，nice')

import time
try:
    f = open('a.txt', 'r')
    try:
        while True:
            content = f.readline()
            #读取完退出
            if len(content) == 0:
                break
            time.sleep(2)
            print(content)
    except:
        pass
        print('强制退出')
    finally:
        f.close()
        print('关闭文件')
except:
    print('没有这个文件')
